package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Demo7 {
    public static void main(String[] args) throws SQLException {
        try ( Connection con=DBUtil.getConnection();){
            Statement statement=con.createStatement();
            String sql="SELECT COUNT(*) count ,AVG(salary) avg_sal "+
                       " FROM teacher ";
            ResultSet res=statement.executeQuery(sql);
            while(res.next()){
              int count= res.getInt("count");
              double avgSla=res.getDouble("avg_sal");
                System.out.println("一共"+count+"人，"+"平均工资为："+avgSla);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
